package com.imonsoft.sqm.web.excel.EnvManageExcel;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.imonsoft.common.constant.CCommon;
import com.imonsoft.common.constant.ConstantSqm;
import com.imonsoft.common.exception.SystemException;
import com.imonsoft.common.httpModel.ReturnMessage;
import com.imonsoft.common.util.AjaxUtil;
import com.imonsoft.common.util.JsonUtil;
import com.imonsoft.common.util.StringUtil;
import com.imonsoft.sqm.service.excel.EnvManageExcel.EnvManageExcelService;

@Controller
@RequestMapping("/excel/envManageExcel")
public class EnvManageExcelController {
	protected final Log logger = LogFactory.getLog(getClass());
	@Autowired
	private EnvManageExcelService envManageExcelService;

	/**
	 * description Excel导出 on 2013-6-4
	 * 
	 * @a uthor zhouwei
	 */
	@RequestMapping(value = "/exportExcel.do", method = RequestMethod.POST)
	public void exportExcel(HttpServletRequest request, String id, HttpServletResponse response) throws Exception {
		try {
			Long tempid=Long.parseLong(StringUtil.fixup(id));
			envManageExcelService.txLoadJustExcel(request, tempid, response);
		} catch (SystemException se) {
			logger.info(se.getMessage());
		} catch (Exception e) {
			logger.error(e.getMessage());
		}
	}
	@RequestMapping(value = "/ajaxSendMail.do", method = RequestMethod.POST)
	public void ajaxSendMail(HttpServletRequest request,HttpServletResponse response) {
		ReturnMessage message = new ReturnMessage();
		try {
			envManageExcelService.txSendMailByDateOut(request,response);
			message.setSuccess(true);
			message.setMsg(ConstantSqm.OPERATE_SUCCESS);
		} catch (SystemException se) {
			logger.debug(this.getClass() + ":" + se.getMessage());
			message.setMsg(se.getMessage());
		} catch (Exception e) {
			logger.error(this.getClass() + ":" + e.getMessage());
			message.setMsg(CCommon.EXCEPTION_MSG);
		}
		AjaxUtil.renderJSON(response, JsonUtil.bean2json(message));
	}
}
